package com.example.kuaizu.utils;


import lombok.Data;
import lombok.NoArgsConstructor;

import static kuaizu.common.constp.KuaiZuConst.ERROR;


/**
 * @author xiaokai
 * 统一响应格式
 */
@Data
@NoArgsConstructor
public class AjaxResponse<T> {
    //响应代码
    private Integer code;
    //响应信息
    private String message;
    //响应数据
    private T  data;
    // 手动添加全参构造函数，确保构造函数正确定义
    public AjaxResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    //快速返回操作成功响应结果(带响应数据)
    public static <E> AjaxResponse<E> success(E data) {
        return new AjaxResponse<>(200, "操作成功", data);
    }

    //快速返回操作成功响应结果
    public static AjaxResponse success() {
        return new AjaxResponse(200, "操作成功", null);
    }

    public static AjaxResponse error(String message) {
        return error(ERROR,message,null);
    }
    public static AjaxResponse error(Integer Code,String message) {
        return error(Code,message,null);
    }
    public static <E> AjaxResponse<E> success(String msg, E data) {return new AjaxResponse(200, msg, data);}
    public static AjaxResponse error(Integer Code ,String message ,Object  data) {
        return new AjaxResponse(Code, message, data);
    }
}
